using System;
using System.Linq.Expressions;

namespace K3Cloud.WebApi.Core.IoC.Extensions
{
    /// <summary>
    /// 表达式优化规则接口
    /// </summary>
    public interface IOptimizationRule
    {
        /// <summary>
        /// 规则名称
        /// </summary>
        string Name { get; }

        /// <summary>
        /// 规则优先级（数字越小优先级越高）
        /// </summary>
        int Priority { get; }

        /// <summary>
        /// 检查规则是否适用于给定的表达式
        /// </summary>
        /// <param name="expression">待检查的表达式</param>
        /// <returns>true表示可以应用此规则</returns>
        bool CanApply(Expression expression);

        /// <summary>
        /// 应用优化规则
        /// </summary>
        /// <param name="expression">原始表达式</param>
        /// <returns>优化后的表达式</returns>
        Expression Apply(Expression expression);
    }
}
